package com.example.seataStorage.controller;

import com.example.seataStorage.common.response.ObjectResponse;
import com.example.seataStorage.service.StorageService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("storage")
@Slf4j
public class StorageController {

    private final StorageService storageService;

    public StorageController(StorageService storageService) {
        this.storageService = storageService;
    }

    /**
     * 扣减库存接口
     *
     * @param commodityCode 产品编号
     * @param count         订单产品数量
     */
    @PostMapping
    @ResponseBody
    public ObjectResponse<Object> deduct(@RequestParam("commodityCode") String commodityCode,
                                 @RequestParam("count") Integer count) {
        log.info("commodityCode参数的值是：{}, count参数的值是：{}", commodityCode, count);
        return storageService.deduct(commodityCode, count);
    }
}
